import { CellRenderer } from "../../../../fl/controls/listClasses/CellRenderer";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { BaseItem } from "../common/BaseItem";
import { ItemData } from "../../resource/info/ItemData";
import { GLabel } from "../../../../com/mui/controls/GLabel";
import { GNumericStepper } from "../../../../com/mui/controls/GNumericStepper";
import { GButton } from "../../../../com/mui/controls/GButton";
import { Language } from "../../../../extend/language/Language";
import { LoaderManager } from "../../../../com/gengine/resource/LoaderManager";
import { ImageInfo } from "../../../../com/gengine/resource/info/ImageInfo";
import { DataEvent } from "../../events/DataEvent";
import { EquipmentModuleConst } from "./data/EquipmentModuleConst";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { ColorConfig } from "../../resource/ColorConfig";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { EPlayerItemPosType } from "../../../../Message/Public/EPlayerItemPosType";
import { EItemUpdateOper } from "../../../../Message/Game/EItemUpdateOper";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { SPlayerItem } from "../../../../Message/Public/SPlayerItem";
import { ShopItemInfo } from "../../resource/info/ShopItemInfo";
import { _buyItemInfo } from "../../../../this/_buyItemInfo";
//class StoneItem
    
    export  class StoneItem extends CellRenderer
    {
        constructor()
        {
            super();
            this.initStyle();
            this.createChildren();
            this.mouseChildren = true;
            this.type = StoneItem.Type_Use;
            return;
        }

        /* internal  */initStyle(): void
        {
            var loc1=GlobalClass.getBitmap("equipment_over");
            this.setStyle("upSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("downSkin", loc1);
            this.setStyle("overSkin", loc1);
            this.setStyle("selectedDownSkin", loc1);
            this.setStyle("selectedOverSkin", loc1);
            this.setStyle("selectedUpSkin", loc1);
            return;
        }

        /* internal  */createChildren(): void
        {
            var loc1=null;
            ObjCreate.createBg(0, 0, 128, 40, this, ImagesConst.DisabledBg);
            this._equipedBm = new Object /* flash.display.Bitmap */();
            this._equipedBm.x = 82;
            this._equipedBm.y = 21;
            this.addChild(this._equipedBm);
            loc1 = GlobalClass.getBitmap("PackItemBg");
            loc1.y = 1.5;
            loc1.x = 1;
            addChild(loc1);
            this.pic = new BaseItem();
            this.pic.isDragAble = false;
            this.pic.isThrowAble = false;
            this.pic.isDropAble = false;
            this.pic.isShowLock = true;
            this.pic.setSize(32, 32);
            this.pic.y = 4.5;
            this.pic.x = 4;
            this.pic.toolTipType = ItemData.ToolTipType_Forge;
            addChild(this.pic);
            this.itemNameLabel = new GLabel();
            this.itemNameLabel.htmlText = "";
            this.itemNameLabel.x = 39;
            this.itemNameLabel.y = 3;
            this.itemNameLabel.width = 90;
            this.itemNameLabel.height = 20;
            this.itemNameLabel.mouseEnabled = false;
            addChild(this.itemNameLabel);
            this.buyNumBg = GlobalClass.getScaleBitmap("WindowCenterB", new Object /* flash.geom.Rectangle */(4, 4, 36, 21));
            this.buyNumBg.height = 16;
            this.buyNumBg.width = 40;
            this.buyNumBg.x = 41;
            this.buyNumBg.y = 22;
            addChild(this.buyNumBg);
            this.numStepper = new GNumericStepper();
            this.numStepper.setSize(47, 16);
            this.numStepper.maximum = 99;
            this.numStepper.minimum = 1;
            this.numStepper.styleName = "NumericStepper";
            this.numStepper.drawNow();
            this.numStepper.textField.y = 0;
            this.numStepper.textField.setStyle("upSkin", new Object /* flash.display.Bitmap */());
            this.numStepper.textField.drawNow();
            this.numStepper.x = 41;
            this.numStepper.y = 22;
            addChild(this.numStepper);
            this.buyButton = new GButton();
            this.buyButton.styleName = "Button";
            this.buyButton.label = Language.getString(60331);
            this.buyButton.width = 38;
            this.buyButton.height = 20;
            this.buyButton.y = 18;
            this.buyButton.x = 84;
            this.buyButton.drawNow();
            this.buyButton.addEventListener(flash.events.MouseEvent.CLICK, this.onBuyButtonClick);
            addChild(this.buyButton);
            this.itemAttrLabel = new GLabel();
            this.itemAttrLabel.htmlText = "";
            this.itemAttrLabel.x = 39;
            this.itemAttrLabel.y = 22;
            this.itemAttrLabel.width = 90;
            this.itemAttrLabel.height = 20;
            this.itemAttrLabel.mouseEnabled = false;
            addChild(this.itemAttrLabel);
            LoaderManager.instance.load("Equipmet_Equiped.png", this.onEquipedImgLoaded);
            return;
        }

        /* internal  */onEquipedImgLoaded(arg1: ImageInfo): void
        {
            this._equipedBm.bitmapData = arg1.bitmapData;
            return;
        }

        /* internal  */set type(arg1: string)
        {
            if (arg1 != StoneItem.Type_Buy) 
            {
                this.buyNumBg.visible = false;
                this.buyButton.visible = false;
                this.numStepper.visible = false;
                this.itemAttrLabel.visible = true;
            }
            else 
            {
                this.buyNumBg.visible = true;
                this.buyButton.visible = true;
                this.numStepper.visible = true;
                this.itemAttrLabel.visible = false;
            }
            return;
        }

        /* internal  */onBuyButtonClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.dispatchEvent(new DataEvent(EquipmentModuleConst.Event_DoBuyEvent, {"shopItemInfo": _buyItemInfo, "amount": this.numStepper.value}, false, true));
            return;
        }

        /* internal  */onDoubleClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            return;
        }

        public get itemData(): ItemData
        {
            return this.pic.itemData;
        }

        public set itemData(arg1: ItemData)
        {
            this._itemData = arg1;
            this.pic.itemData = this._itemData;
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=0;
            var loc2=null;
            var loc3=null;
            var loc4=0;
            var loc5=0;
            var loc6=null;
            var loc7=0;
            var loc8=0;
            var loc9=0;
            super.data = arg1;
            this._equipedBm.visible = false;
            if (arg1) 
            {
                this.type = arg1["type"];
                if (arg1["type"] != StoneItem.Type_Buy) 
                {
                    this.itemData = arg1["data"];
                    if (arg1["used"]) 
                    {
                        this.filters = [FilterConst.colorFilter2];
                    }
                    else 
                    {
                        this.filters = [];
                    }
                    if (this._itemData) 
                    {
                        loc3 = ColorConfig.instance.getItemColor(this._itemData.itemInfo.item.color);
                        this.itemNameLabel.htmlText = ItemsUtil.getItemName(this._itemData);
                        if (arg1["type"] != "equipment") 
                        {
                            if (arg1["embed"]) 
                            {
                                this.itemAttrLabel.htmlText = ItemsUtil.getItemName(arg1["equip"]);
                            }
                            else 
                            {
                                this.itemAttrLabel.htmlText = "";
                            }
                        }
                        else 
                        {
                            if (this._itemData.posType == EPlayerItemPosType._EPlayerItemPosTypeRole || this._itemData.posType >= EPlayerItemPosType._EPlayerItemPosTypePetEquipBase) 
                            {
                                this._equipedBm.visible = true;
                            }
                            if (arg1["operationType"] == EItemUpdateOper._EItemUpdateOperStrengthen || arg1["operationType"] == EItemUpdateOper._EItemUpdateDecompose || arg1["operationType"] == EItemUpdateOper._EItemUpdateStrengthenShift || arg1["operationType"] == EItemUpdateOper._EItemUpdateOperRecast) 
                            {
                                loc4 = 0;
                                if (this._itemData.itemExInfo.strengthen) 
                                {
                                    loc4 = this._itemData.itemExInfo.strengthen;
                                }
                                this.itemAttrLabel.htmlText = HTMLUtil.addColor(Language.getString(60332) + loc4, loc3.color);
                            }
                            else if (arg1["operationType"] == EItemUpdateOper._EItemUpdateOperAdvance || arg1["operationType"] == EItemUpdateOper._EItemUpdateOperEquipSmelt) 
                            {
                                this.itemAttrLabel.htmlText = HTMLUtil.addColor(this._itemData.itemInfo.item.level + Language.getString(60333), loc3.color);
                            }
                            else if (arg1["operationType"] != EItemUpdateOper._EItemUpdateOperRefine) 
                            {
                                if (arg1["operationType"] == EItemUpdateOper._EItemUpdateUpdradePrefix || arg1["operationType"] == EItemUpdateOper._EItemUpdatePetEquipUpgradePrefix) 
                                {
                                    loc6 = GameDefConfig.instance.getEPrefixx(this._itemData.itemExInfo.prefix, this._itemData.type);
                                    this.itemAttrLabel.htmlText = HTMLUtil.addColor(loc6 ? loc6.name : "", loc3.color);
                                }
                                else if (arg1["operationType"] != EItemUpdateOper._EItemUpdateOperMakeHole) 
                                {
                                    if (arg1["operationType"] == EItemUpdateOper._EItemUpdateOperEmbedJewel || arg1["operationType"] == EItemUpdateOper._EItemUpdateComposeJewel || arg1["operationType"] == EItemUpdateOper._EItemUpdateOperRemoveJewel) 
                                    {
                                        loc8 = 0;
                                        loc9 = 0;
                                        loc1 = 1;
                                        while (loc1 <= 6) 
                                        {
                                            if (this._itemData.itemExInfo["hole" + loc1] != 0) 
                                            {
                                                ++loc8;
                                                if (this._itemData.itemExInfo["hole" + loc1] != 1) 
                                                {
                                                    ++loc9;
                                                }
                                            }
                                            ++loc1;
                                        }
                                        this.itemAttrLabel.htmlText = HTMLUtil.addColor(Language.getString(60336) + loc9 + "/" + loc8, loc3.color);
                                    }
                                    else if (arg1["operationType"] == EItemUpdateOper._EItemUpdatePetEquipUpgradeStar || arg1["operationType"] == EItemUpdateOper._EItemUpdatePetEquipRecast) 
                                    {
                                        this.itemAttrLabel.htmlText = HTMLUtil.addColor(Language.getString(61323) + "  " + (this._itemData.itemExInfo ? this._itemData.itemExInfo.p_equip_star : "0"), loc3.color);
                                    }
                                    else 
                                    {
                                        this.itemAttrLabel.htmlText = "";
                                    }
                                }
                                else 
                                {
                                    loc7 = 0;
                                    loc1 = 0;
                                    while (loc1 < 3) 
                                    {
                                        if (this._itemData.itemExInfo["hole" + (loc1 + 1)] != 0) 
                                        {
                                            ++loc7;
                                        }
                                        ++loc1;
                                    }
                                    this.itemAttrLabel.htmlText = HTMLUtil.addColor(Language.getString(60335) + loc7 + "/3", loc3.color);
                                }
                            }
                            else 
                            {
                                loc5 = 0;
                                if (this._itemData.itemExInfo.refine) 
                                {
                                    loc5 = this._itemData.itemExInfo.refine;
                                }
                                this.itemAttrLabel.htmlText = HTMLUtil.addColor(Language.getString(60334) + loc5, loc3.color);
                            }
                        }
                    }
                }
                else 
                {
                    if (arg1["isUpdate"] != 1) 
                    {
                        arg1["isUpdate"] = 1;
                        this.numStepper.value = 1;
                    }
                    this._buyItemInfo = arg1["data"];
                    loc2 = new SPlayerItem();
                    loc2.itemCode = this._buyItemInfo.itemInfo.item.code;
                    this.itemData = new ItemData(loc2);
                    if (this._buyItemInfo) 
                    {
                        this.itemNameLabel.htmlText = ItemsUtil.getItemName(this._itemData);
                    }
                }
            }
            else 
            {
                this.pic.source;
            }
            return;
        }

        public /* override */ set label(arg1: string)
        {
            return;
        }

        public dispose(): void
        {
            return;
        }

        public static /* const */Type_Buy: string="buy";

        public static /* const */Type_Use: string="use";

        /* internal */ /* var */_source: string;

        /* internal */ /* var */pic: BaseItem;

        /* internal */ /* var */itemNameLabel: GLabel;

        /* internal */ /* var */itemAttrLabel: GLabel;

        /* internal */ /* var */buyButton: GButton;

        /* internal */ /* var */_itemData: ItemData;

        /* internal */ /* var */_buyItemInfo: ShopItemInfo;

        /* internal */ /* var */numStepper: GNumericStepper;

        /* internal */ /* var */buyNumBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_equipedBm: Object /* flash.display.Bitmap */;
    }
